home *** CD-ROM | disk | FTP | other *** search
- Path: inforamp.net!ts10-07
- From: rmorin@inforamp.net (Randy Charles Morin)
- Newsgroups: comp.lang.c++
- Subject: Re: Question about visibility of local variables
- Date: Sat, 09 Mar 96 18:00:36 GMT
- Organization: MiddleWorld SoftWare
- Message-ID: <4hsh0g$pmm@sam.inforamp.net>
- References: <4hgufv$48h@hpbblb.bbn.hp.com> <4hifc6$hm5@news1.usa.pipeline.com> <4hj56k$elu@sam.inforamp.net> <313E7807.5CC2@parashift.com>
- NNTP-Posting-Host: ts10-07.tor.inforamp.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <313E7807.5CC2@parashift.com>,
- Mike Girou <girou@parashift.com> wrote:
- >Well, maybe. Certainly that was the way we did things in C. But
- >there has been quite a lot written about declaring/defining at first
- >use, particularly with class variables. These arguments include
- >possible efficiency and the notion that variables needed to properly
- >initialize may not be known when the "block" is entered.
-
- I agree completely. Sometimes, it is better to declare the variable later on
- in a block. But it is much more efficient to add blocks.
-
- Example:
-
- {
- BIGCHUNKOFMEMORY a,b,c;
- ...
- a=
- ...
- b=
- ...
- c=
- ...
- }
-
- ..could also be ...
-
- {
- ...
- BIGCHUNKOFMEMORY a=
- ...
- BIGCHUNKOFMEMORY b=
- ...
- BIGCHUNKOFMEMORY c=
- ...
- }
-
- ..but this is also inefficient.
-
- Instead of declaring stuff half way through a block,
- it is better to add blocks...
-
- {
- ...
- {
- BIGCHUNKOFMEMORY a=
- ...
- }
- {
- BIGCHUNKOFMEMORY b=
- ...
- }
- {
- BIGCHUNKOFMEMORY c=
- ...
- }
- }
-
- This is much more efficient then the previous and it is easier to read a block
- since the variables will be declared at the beginning of the block.
-
- Agrivar
-